#include "StdAfx.h"
#include "Point2D.h"


Point2D::Point2D(int x, int y) : x(x), y(y)
{
}


Point2D::~Point2D(void)
{
}

int Point2D::GetX() const
{
	return this->x;
}

void Point2D::SetX(int value)
{
	this->x = value;
}


int Point2D::GetY() const
{
	return this->y;
}

void Point2D::SetY(int value)
{
	this->y = value;
}

Point2D Point2D::operator+(const Point2D& a) const
{
	
	return Point2D(this->GetX() + a.GetX(), this->GetY() + a.GetY());
}

Point2D Point2D::operator-(const Point2D& a) const
{
	return Point2D(this->GetX() - a.GetX(), this->GetY() - a.GetY());
}

Point2D Point2D::operator*(const Point2D& a) const
{
	return Point2D(this->GetX() * a.GetX(), this->GetY() * a.GetY());
}

Point2D Point2D::operator/(const Point2D& a) const
{
	if(a.GetX() == 0 || a.GetY() == 0)
		return *this;
	return Point2D(this->GetX() / a.GetX(), this->GetY() / a.GetY());
}

void Point2D::operator+=(Point2D a)
{
	this->x += a.GetX();
	this->y += a.GetY();
}

void Point2D::operator-=(Point2D a)
{
	this->x -= a.GetX();
	this->y -= a.GetY();
}

void Point2D::operator*=(Point2D a)
{
	this->x *= a.GetX();
	this->y *= a.GetY();
}

void Point2D::operator/=(Point2D a)
{
	if(a.GetX() != 0)
		this->x /= a.GetX();

	if(a.GetY() != 0)
		this->y /= a.GetY();
}

void Point2D::operator+=(int a)
{
	this->x += a;
	this->y += a;
}

void Point2D::operator-=(int a)
{
	this->x -= a;
	this->y -= a;
}

void Point2D::operator*=(int a)
{
	this->x *= a;
	this->y *= a;
}

void Point2D::operator/=(int a)
{
	if(a)
	{
		this->x /= a;
		this->y /= a;
	}
}

Point2D Point2D::min(Point2D& a, Point2D& b)
{
	int x = a.GetX();
	int y = a.GetY();

	if(x > b.GetX())
		x = b.GetX();

	if(y > b.GetY())
		y = b.GetY();

	return Point2D(x,y);
}
	
Point2D Point2D::max(Point2D& a, Point2D& b)
{
	int x = a.GetX();
	int y = a.GetY();

	if(x < b.GetX())
		x = b.GetX();

	if(y < b.GetY())
		y = b.GetY();

	return Point2D(x,y);
}